package deployr.core;

import static java.text.MessageFormat.*;

public class Progress {

	private final double end;

	private double now = 0;

	public Progress(double end) {
		this.end = end;
		this.now = 0;
	}

	public Progress(double end, double now) {
		this.end = end;
		this.now = now;
	}

	public double add(double i) {
		now += i;
		if (now > end) now = end;
		return now();
	}

	public double end() {
		return end;
	}

	public Progress newProgress(double end) {
		return new Progress(end, now * end / end());
	}

	public double now() {
		return now;
	}

	public String percent() {
		double percent = now * 100 / end;
		if (percent > 100) percent = 100;
		if (percent < 0) percent = 0;
		return format("{0}%", new Integer((int) percent).toString());
	}

}
